package com.lglbc.protype.deep.serializable;

import java.io.*;
/**
 * @author： 乐哥聊编程(全平台同号)
 */
public class Student implements Cloneable, Serializable {
    private String name;
    private String email;
    private String address;
    private Teacher teacher;

    public Student(String name, String email, String address) {
        this.name = name;
        this.email = email;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    protected Student clone() {

        ByteArrayOutputStream byteArrayOutputStream =null;
        ObjectOutputStream objectOutputStream =null;
        ByteArrayInputStream byteArrayInputStream =null;
        ObjectInputStream objectInputStream =null;
            try {
                 byteArrayOutputStream = new ByteArrayOutputStream();
                 objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
                objectOutputStream.writeObject(this);

                 byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                 objectInputStream = new ObjectInputStream(byteArrayInputStream);
                Student student = (Student)objectInputStream.readObject();
                return student;
            } catch (Exception e) {
                e.printStackTrace();
            }finally {
                try {
                    byteArrayOutputStream.close();
                    byteArrayInputStream.close();
                    objectOutputStream.close();
                    objectInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        return null;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", email='" + email + '\'' +
                ", address='" + address + '\'' +
                ", teacher=" + teacher +
                '}';
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }
}
